package com.lhh.springcloud.controller;

import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;

/**
 * @author 李洪豪
 * @Sno 20220301044
 * 资源清洗方式限流：此类为了将/member/query/*统一进行流量控制
 */
@Component
public class CustomUrlCleaner implements UrlCleaner {
    @Override
    public String clean(String originUrl) {
        if (StringUtils.isEmpty(originUrl)){
            return originUrl;
        }
        if (originUrl.startsWith("/member/query")){
            //如果请求的接口是/member/query开头的(比如member/query/1;member/query/2)，
            // 则将请求的接口改为member/query/*
            return "member/query/*";
        }
        return originUrl;
    }
}
